package com.example.administrator.reader.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.RelativeLayout;

import com.example.administrator.reader.R;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;

public class SplashActivity extends Activity {

    @ViewInject(R.id.rl)
    RelativeLayout relativeLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        ViewUtils.inject(this);
        /**
         * 1、调节透明度
         * 2、当透明读到0时，调整页面
         */
        startAnim();
    }

    /**
     * 开始实现动画
     */
    private void startAnim() {
        AlphaAnimation alphaAnimation = new AlphaAnimation(0, 1);
        // 设置透明编号的时间
        alphaAnimation.setDuration(2000);
        alphaAnimation.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                startActivity(new Intent(SplashActivity.this, MainActivity.class));
                // 删除开场页面
                finish();
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
        // 开始动画
        relativeLayout.startAnimation(alphaAnimation);
    }
}
